home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Expander / Expander Classes / CColumnizer.cp next >
Encoding:
Text File  |  1994-11-30  |  2.7 KB  |  97 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.     CColumnizer.cp
  3.  
  4.     Copyright © 1994 B-Ray Software. All rights reserved.
  5.     Developed using Symantec C++ 7.0 and Symantec's TCL library.
  6.     Portions of this code courtesy Symantec, Inc.
  7.  
  8.     This code may be freely distributed as long as this notice remains. The code
  9.     may not be used in any commercial software without the consent of B-Ray Software.
  10.  
  11.     ---
  12.  
  13.     The Columnizer class provides vertical position management for child panes
  14.     of a particular parent. This class simply defines 3 functions that are
  15.     pure virtual in the RowColumnMgr class. These functions work with with vertical
  16.     values, compared to the Rowizer class which works with horizontal values -- 
  17.     that is the only difference between the two.
  18.  
  19. ***********************************************************************************/
  20.  
  21. #include "CColumnizer.h"
  22.  
  23.  
  24. TCL_DEFINE_CLASS_M1( CColumnizer, CRowColumnMgr );
  25.  
  26.  
  27. /*
  28.  *    PositionChild
  29.  *
  30.  *    Adjust a child's position so that it is situated properly among its siblings.
  31.  */
  32.  
  33. void CColumnizer :: PositionChild( CPane *aChild, long index )
  34. {
  35.     long    numItems = GetNumberChildren();
  36.  
  37.     aChild->Prepare();
  38.  
  39.     if ( index < 2 ) {                    // become first child in list
  40.         aChild->Place( aChild->hEncl, 0, FALSE );
  41.     }
  42.     else if ( index > numItems ) {        // become last child in list
  43.         CPane    *lastPane = GetChildAtIndex( numItems )->ChildToPane();
  44.         aChild->Place( aChild->hEncl, lastPane->vEncl + lastPane->height, FALSE );
  45.     }
  46.     else {                                // somewhere in between...
  47.         CPane    *beforePane = GetChildAtIndex( index )->ChildToPane();
  48.         aChild->Place( aChild->hEncl, beforePane->vEncl, FALSE );
  49.     }
  50. }
  51.  
  52.  
  53. /*
  54.  *    AdjustDelta
  55.  *
  56.  *    Zaps out unused portions of the given Rect parameter. RowColumnMgr calls this
  57.  *    function but does not define one, so we must. Zero out all values but the
  58.  *    vertical size amount (delta->bottom).
  59.  */
  60.  
  61. void CColumnizer :: AdjustDelta( Rect *delta )
  62. {
  63.     delta->left = delta->top = delta->right = 0;
  64. }
  65.  
  66.  
  67. /*
  68.  *    GetFamilySize
  69.  *
  70.  *    Calculates and returns the dimensions of the smallest rectangle to enclose all
  71.  *    of the children.
  72.  */
  73.  
  74.     static void FindChildSize( CFamily *aChild, long param )
  75.     {
  76.         CPane        *aPane;
  77.         Point        *aPt = (Point *)param;
  78.         short        aWidth, aHeight;
  79.  
  80.         aPane = aChild->ChildToPane();                // get CPane part of object
  81.         aPane->GetLengths( &aWidth, &aHeight );        // get its dimensions
  82.         aWidth += aPane->hEncl;                        // take into account any offset
  83.         if ( aWidth > aPt->h ) aPt->h = aWidth;
  84.         aPt->v += aHeight;                            // increase the parent's height
  85.     }
  86.  
  87. void CColumnizer :: GetFamilySize( short *aWidth, short *aHeight )
  88. {
  89.     Point    aPt = { 0, 0 };
  90.  
  91.     if ( itsChildren )
  92.         itsChildren->DoForEach1( FindChildSize, (long )&aPt );
  93.  
  94.     *aWidth = aPt.h;
  95.     *aHeight = aPt.v;
  96. }
  97.